package com.dura.test;

import com.dura.test.client.CacheClient;
import com.dura.test.mapper.ChannelMapper;
import com.dura.test.pojo.Channel;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;

/**
 * @version 1.0
 * @Author 振鹏
 * @Date 2025/3/18 9:34
 * @注释
 */
@SpringBootTest
@RunWith(SpringRunner.class)
class ChannelMapperTest {

    @Autowired
    private ChannelMapper mapper;

    @Autowired
    private CacheClient cacheClient;


    @Test
    public void findAll() throws JsonProcessingException {
        List<Channel> list = mapper.findAll();
        for (Channel channel : list) {
            ObjectMapper objectMapper = new ObjectMapper();
            Map map = objectMapper.readValue(objectMapper.writeValueAsString(channel), Map.class);
            cacheClient.hmset("channel:" + channel.getId(),map);
        }
    }
}